<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>评价</title>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/evaluate.css"/>
</head>
<body>
    <div class="container" id="returnindex">
        <div class="row">
            <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9"></div>
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1" id="returnshop"></div>
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1" id="ordermanage"></div>
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"><a href="index.html">返回首页</a></div>
        </div>
    </div>
    <div class="container" id="pagetitle">
        <div class="row">
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"><p id="titlep"><span>乐享生活</span>&nbsp;评价商品</p></div>
            <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5"></div>
            <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2"></div>
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
        </div>
    </div>
    <div class="container" id="evaluatebody">
    </div>

    <script type="text/javascript">

        var id = location.search.split("=")[1];

        var userId = $.cookie("userId");

        $.post("order/findById",{id:id},function (data) {

            data = JSON.parse(data);

            var ht = '<div class="row">\n' +
                '          <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 title">商品</div>\n' +
                '          <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 title">类型</div>\n' +
                '          <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 title">单价</div>\n' +
                '          <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 title">数量</div>\n' +
                '     </div>\n' +
                '     <div class="row">\n' +
                '          <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 goodsimg"><img src="/FVOnline/goods/getImg?goodsId='+ data.goodsId +'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+ data.goods.goodsname +'&nbsp;&nbsp;&nbsp;&nbsp;'+ data.goods.details +'</div>\n' +
                '          <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 goods">'+ data.goods.type +'</div>\n' +
                '          <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 goods">￥'+ data.goods.price +'</div>\n' +
                '          <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 goods">'+ data.tradeNum +'</div>\n' +
                '     </div>\n' +
                '     <div class="row">\n' +
                '          <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 evaluate">\n' +
                '               填写评价：<textarea id="evaluate"></textarea>\n' +
                '          </div>\n' +
                '     </div>\n' +
                '     <div class="row">\n' +
                '          <button id="submitevaluate">发表</button>\n' +
                '     </div>';

            $("#evaluatebody").html(ht);

            var goodsId = data.goodsId;

            $("#submitevaluate").click(function () {
                var evaluate = $("#evaluate").val()
                if (evaluate.length <= 0){
                    alert("请填写评价！");
                }else {
                    $.get("evaluate/saveEvaluate",{evaluate:evaluate,userId:userId,goodsId:goodsId},function (data) {
                        data = JSON.parse(data);

                        if (data.code.toLowerCase() == "success"){
                            $.get("order/evaluate",{id:id},function (data1) {
                                data1 = JSON.parse(data1);

                                if (data1.code.toLowerCase() == "success"){
                                    alert("评价成功");
                                    location.href = "myorder.html?page=1";
                                } else {
                                    alert("评价失败！");
                                }
                            });
                        } else {
                            alert("评价失败！");
                        }
                    });
                }
            });


        });
    </script>
</body>
</html>